import 'dart:async';
import 'package:latlong2/latlong.dart';

///模拟轨迹

final List<LatLng> _mockPath = [
  LatLng(31.2304, 121.4737), // 上海
  LatLng(31.2310, 121.4800),
  LatLng(31.2320, 121.4850),
  LatLng(31.2330, 121.4900),
  LatLng(31.2340, 121.4950),
];

final Duration time = Duration(seconds: 5);


class _SimulateFontPrints {
  StreamController _controller = StreamController();

  List<LatLng> paths = [];

  void addFootPrints(LatLng latlng) {
    paths.add(latlng);
    _controller.add(null);
  }

  Stream stream() {
    return _controller.stream;
  }

}

var _footPrints = _SimulateFontPrints();

Stream simulateFootPrints() {
  int count = 0;

  Timer.periodic(time, (timer) {
    if(count >= _mockPath.length) {
      timer.cancel();
    }
    _footPrints.addFootPrints(_mockPath[count++]);
  });

  return _footPrints.stream();
}

List<LatLng> getSimulatePoints() {
  return _footPrints.paths;
}